package IEFYP.JunkCallFiltering;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import IEFYP.JunkCallFiltering.DBhelper;


/****
 * 
 * <Button
android:id="@+id/m_prompt"
android:layout_width="274px"
android:layout_height="42px"
android:text="Test Button"
android:textStyle="bold"
android:textColor="#ff666666"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5px"
>
</Button>
 * 
 * 
 *  1. check user identity!!! device ID
 * @author KOLee
 *
 */


public class JunkCallKiller extends Activity {
	private Button b_report;
	private Button b_action;
	private Button b_history;
	private Button b_blacklist;
	private Button b_startauto;
	private Button b_stopauto;
	private Button b_registration;
	public static boolean serviceStart;
	//private Button b_prompt; //Testing
	DBhelper dbhelper;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        createDatabase();
        findView();
        setOnClickListener();
    }
    
    @Override
    protected void onDestroy(){
    	super.onDestroy();
    //	this.stopService(new Intent(this,AutoReport.class));
    }
    
    private void createDatabase(){
    	
    	dbhelper = new DBhelper(this,"blacklist");
    	
    	
    }
    
    private void findView(){
    	b_report= (Button)findViewById(R.id.m_report);
    	b_action= (Button)findViewById(R.id.m_actions);
    	b_history= (Button)findViewById(R.id.m_history);
    	b_blacklist= (Button)findViewById(R.id.m_blacklist);
    	b_startauto = (Button)findViewById(R.id.m_startauto);
    	b_stopauto = (Button)findViewById(R.id.m_stopauto);
    	b_registration = (Button)findViewById(R.id.m_reg);
    	if(serviceStart){
    		b_startauto.setVisibility(4);//INVISIBLE
    	}else{
    		b_stopauto.setVisibility(4);//INVISIBLE
    	}
    	//b_prompt= (Button)findViewById(R.id.m_prompt);  //testing
    }
    
    
    private void setOnClickListener(){
        b_report.setOnClickListener(gotoReport);
        b_action.setOnClickListener(gotoAction);
        b_history.setOnClickListener(gotoHistory);
        b_blacklist.setOnClickListener(gotoBlacklist);
        b_startauto.setOnClickListener(gotoStartAutoReport);
        b_stopauto.setOnClickListener(gotoStopAutoReport);
        b_registration.setOnClickListener(gotoResgistration);
        //b_prompt.setOnClickListener(gotoPrompt); //testing
    }
/*******************
    private OnClickListener gotoPrompt = new OnClickListener() //testing
    {
            public void onClick(View v)
            {        	     
            	dbhelper.OpenDB();
            	Cursor cursor = dbhelper.loadAll();
            	cursor.moveToFirst();
            	int c = cursor.getColumnIndex("call_no");
            	String s = cursor.getString(c);
            	Log.v("cursor",s);
            	Toast.makeText(getApplicationContext(),"abc:"+s, Toast.LENGTH_LONG).show();
            	dbhelper.close();        
           }
       };
/****************/
    private OnClickListener gotoStartAutoReport = new OnClickListener() //testing
    {
            public void onClick(View v)
            {   
            	serviceStart = true;
            	Intent intent = new Intent();
            	intent.setClass(JunkCallKiller.this, AutoReport.class);          	
            	startService(intent); 
            	b_startauto.setVisibility(4);//INVISIBLE
            	b_stopauto.setVisibility(0);//VISIBLE
           }
       };
       private OnClickListener gotoStopAutoReport = new OnClickListener() //testing
       {
               public void onClick(View v)
               {   
            		serviceStart = false;
            	Intent intent = new Intent();
               	intent.setClass(JunkCallKiller.this, AutoReport.class);          	
               	stopService(intent); 
               	b_stopauto.setVisibility(4);//INVISIBLE
               	b_startauto.setVisibility(0);//VISIBLE
              }
          };
          
       
       private OnClickListener gotoResgistration = new OnClickListener() //testing
       {
               public void onClick(View v)
               {        	     
            	   
              }
          };
       
    
    
    private OnClickListener gotoReport = new OnClickListener()
  {
          public void onClick(View v)
          {
        	  
        	              
             Intent intent = new Intent();
             intent.setClass(JunkCallKiller.this, ReportJunkCall.class);
              Bundle bundle = new Bundle();
              bundle.putBoolean("FromPrompt", false);
              intent.putExtras(bundle);
             startActivity(intent);
                       
         }
     };
    private OnClickListener gotoAction = new OnClickListener()
     {
             public void onClick(View v)
             {
           	  
           	              
                Intent intent = new Intent();
                intent.setClass(JunkCallKiller.this, ActionOnCalls.class);
               // Bundle bundle = new Bundle();
               // bundle.putString("REPORT_RESULT", getText(R.string.bmi_result) +" "+ nf.format(BMI));
                startActivity(intent);
                          
            }
        };
    private OnClickListener gotoHistory = new OnClickListener()
        {
                public void onClick(View v)
                {
              	  
              	              
                   Intent intent = new Intent();
                   intent.setClass(JunkCallKiller.this, ReportedHistory.class);
                  // Bundle bundle = new Bundle();
                  // bundle.putString("REPORT_RESULT", getText(R.string.bmi_result) +" "+ nf.format(BMI));
                   startActivity(intent);
                             
               }
           };
    private OnClickListener gotoBlacklist = new OnClickListener()
           {
                   public void onClick(View v)
                   {
                 	  
                 	              
                      Intent intent = new Intent();
                      intent.setClass(JunkCallKiller.this, BlacklistController.class);
                     // Bundle bundle = new Bundle();
                     // bundle.putString("REPORT_RESULT", getText(R.string.bmi_result) +" "+ nf.format(BMI));
                      startActivity(intent);
                                
                  }
              };
           
    
   



}
